/**
 * \file test.h
 * \brief fonctions de test avec le fichier villes.vl
 * \author 
 * \version 0.1
 * \date 25/12/2013
 *
 * Ce fichier contient les fonctions des testes sur les fonctions du 
 * fichier tsm.c 
 *
 */

 
//#ifndef TSM
//#define TSM 
//#include"tsm.h"
//#endif
#include"tsm.h"
#include<string.h>
#include<stdlib.h>

int Test_load_file(char* file_name)
{
	FILE *file=fopen(file_name,"r");
	City *city = load_file(file_name);
	/*FIXME*/
	fclose(file);
	return 0;
}
int Test_load_nbr_city(char* file_name)
{
	int a;
	FILE *file=fopen(file_name,"r");
	a=load_nbr_city(file);
	fclose(file);
	if(a==5) return 0;
	else return -1;

}
int Test_test_struct_file()
{
	FILE *file=fopen("villes.vl","r");
	int ret=test_struct_file(file);
	fclose(file);
	return 0;
}
double Test_campute_dst()
{
	City city1,city2;
	double dist;
	city1.x=0;
	city1.y=0;
	city2.x=0;
	city2.y=10;
	dist=campute_dst(city2,city1);
	if(dist==10) return 0;
	else return -1;
	
}
int Test_add_city()
{
	Path *p;
	p=NULL;

	City c;
	c.name = (char*) malloc( sizeof(char) * 3);
	strcpy(c.name,"cc");
	c.x=2; c.y=2;
	
	City b;
	b.name = (char*) malloc( sizeof(char) * 3);
	strcpy(b.name,"bb");
	b.x=1; b.y=1;
	
	City a;
	a.name = (char*) malloc( sizeof(char) * 3);
	strcpy(a.name,"aa");
	a.x=0; a.y=0;
	
	p=add_city(p,a);
	p=add_city(p,b);
	p=add_city(p,c);
	if(strcmp((p->city).name,"aa")==0 && (p->city).x==0 && (p->city).y==0 )
	{
		p=p->next;
		if(strcmp((p->city).name,"bb")==0 && (p->city).x==1 && (p->city).y==1 )
		{
			p=p->next;
			if(strcmp((p->city).name,"cc")==0 && (p->city).x==2 && (p->city).y==2 )
				return 0;
		}
	}
	
	return -1;
}
int Test_test_nbr_city(char* file_name)
{
	FILE *file=fopen(file_name,"r");
	test_nbr_city(file);	
	/*FIXME*/
	fclose(file);
	return 0;
	// theo
	
}
int Test_test_file()
{
	FILE *file=fopen("villes.vl","r");
	int ret = test_file(file);
	
	fclose(file);
	return ret;
}
int Test_next_line(char* file_name)
{
	FILE *file=fopen(file_name,"r");
	int c;
	next_line(file);
	if((c=fgetc(file))=='5') return 0; 
	else return -1;
	fclose(file);
}
int main()
{
	//FILE *file=fopen("villes.vl","r");
	//nbr_city=load_nbr_city(file);
	City *c;
	c=load_file("villes.vl");
	
	
	
	if(Test_load_nbr_city("villes.vl")==0) printf("*****la fct load_nbr_city est correcte*****\n");
	else printf("*****la fct load_nbr_city est incorrecte*****\n");
	
	if(Test_next_line("villes.vl")==0) printf("*****la fct next_line est correcte*****\n");
	else printf("*****la fct next_line est incorrecte*****\n");
	
	if(Test_campute_dst()==0) printf("*****la fct comput_dist est correcte*****\n");
	else printf("*****la fct comput_dist est incorrecte*****\n");
	
	if(Test_test_struct_file()==0) printf("*****la fct Test_test_struct_file() est correcte*****\n");
	else printf("*****la fct Test_test_struct_file() est incorrecte*****\n");

	if(Test_test_file()==0) printf("*****la fct Test_test_file() est correcte*****\n");
	else printf("*****la fct Test_test_file() est incorrecte*****\n");
	
	if(Test_add_city()==0) printf("*****la fct Test_add_city() est correcte*****\n");
	else printf("*****la fct Test_add_city() est incorrecte*****\n");
	
	print_all_city(c);
	//fclose(file);

}
